<template>
  <div>
    <div class="container">
      <div class="left">职&nbsp;<i></i>&nbsp;统</div>
      <div @click="toggleMyMenu()" class="right">{{$store.state.user.user.employeename}}</div>
      <div @click="gotoMain()" class="right">首页</div>

      <div v-show="$store.state.isShowMyMenu" class="my-alert">
        <!-- <div @click="optchange(1)">修改密码</div> -->
        <div @click="optchange(0)">退出登录</div>
      </div>
    </div>
  </div>
</template>

<script>
// import {removeRequestParams} from '@/request'

export default {
  name:"topMenu",
  data() {
    return {}
  },
  methods: {
    toggleMyMenu() {
      this.$store.commit('toggleIsShowMyMenu')
    },
    async optchange(type){
      if(type === 0) {
        const {code,msg} = await this.$post('/outlogin')
        if(code === 200) {
          this.$store.commit('user/clearUser')
          localStorage.removeItem('username')
          localStorage.removeItem('role')
          localStorage.removeItem('userinfo')
          localStorage.removeItem('navInfo')
          this.$message.success(msg)
          // removeRequestParams()
          if(this.$router.currentRoute.path.search('/admin') === 0) {
            // 从后台退出
            this.$router.push('/login/admin')
          } else {
            //从前台退出
            this.$router.push('/login')
          }
        }else {
          this.$message.error(msg)
        }
      } else {
        console.log('修改密码')
      }
    },
    gotoMain(){
      this.$router.push('/main/nav')
    }
  }
}
</script>

<style scoped lang="scss">
$color1: #0063af;

.container {
  position: relative;

  .my-alert {
    position: absolute;
    z-index: 1111;
    right: 0;
    top: 50px;
    background: white;
    text-align: center;
    font-size: 13px;
    color: $color1;
    // border: 1px solid gray;

    div {
      padding: 12px 0;
      box-sizing: border-box;
      width: 100px;
    }
  }

  &::after {
    content: '';
    display: block;
    clear: both;
  }

  .left {
    float: left;
    margin-left: 50px;
    width: 80px;
    height: 50px;
    line-height: 50px;
    font-size: 20px;
    cursor: pointer;


    i {
      display: inline-block;
      width: 7px;
      height: 7px;
      border-radius: 50%;
      position: relative;
      background: black;
      top: -2px;
    }
  }

  .right {
    padding: 10px;
    box-sizing: border-box;
    float: right;
    height: 50px;
    line-height: 30px;
    cursor: pointer;

    &:nth-child(2) {
      margin-right: 30px;
    }
  }

}


</style>